package io.renren.config;

import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyApplicationContextUtil implements ApplicationContextAware {

	private static ApplicationContext ct;
	
	public static void setContext(ApplicationContext context) {
		MyApplicationContextUtil.ct = context;
	}
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		ct = applicationContext;
	}
	
	public static ApplicationContext getContext() {
		return ct;
	}

	public final static Object getBeanObj(String beanName) {
		return ct.getBean(beanName);
	}
	
	public final static Object getBeanObj(String beanName, Class<?> requiredType) {
		return ct.getBean(beanName, requiredType);
	}
	
	public final static <T> Map<String, T> getBeanOfType(Class<T> clazz){
		return ct.getBeansOfType(clazz);
	}
}
